package com.cash.app.ui.other

import androidx.lifecycle.MutableLiveData
import com.cash.app.base.BaseViewModel
import com.cash.app.constant.AppConstant.K_APP_CHECK
import com.cash.app.constant.AppConstant.K_APP_LOGIN
import com.cash.app.constant.AppConstant.K_WX_CODE
import com.cash.app.manager.AccountInfoManager
import com.cash.app.manager.GlobalTaskManager
import com.cash.app.manager.LoginManager
import com.cash.app.manager.api.GlobalAPIService
import com.cash.app.net.NetRequestExecutor
import com.cash.app.net.RetrofitClient
import com.cash.app.utils.SpUtils

class SettingViewModel : BaseViewModel() {
    private val globalAPIService by lazy {
        RetrofitClient.createService(GlobalAPIService::class.java)
    }

    val quitSuccess = MutableLiveData<Boolean>()

    fun appQuit() {
        launchRequest(request = {
            NetRequestExecutor.baseNetRequest {
                globalAPIService.appQuit()
            }
        }, onSuccess = { response ->
            response?.let {
                quitSuccess.value = true
                LoginManager.clear()
                AccountInfoManager.clear()
                SpUtils.remove(K_WX_CODE)
                SpUtils.remove(K_APP_LOGIN)
                SpUtils.remove(K_APP_CHECK)
                GlobalTaskManager.getTempToken()
            }
        })
    }
} 